using System;
using UnityEngine;
using FrameOperateSync;

namespace Pvp
{
    public class PvpInit : MonoBehaviour,IFrameLoger,IFrameParser
    {
        private void Awake()
        {
            HelperUtility.SetLogger(this);
            HelperUtility.SetFrameParser(this);
            HelperUtility.SetSetting("siglePlayerMode", true);
            if (!HelperUtility.SinglePlayerMode)
            {
                var networkClient = gameObject.GetComponent<NetworkClient>();
                networkClient.StartNetwork();
                ClientUtility.StartSync(networkClient, null, a => { a?.Invoke(); });
            }
            else
            {
                Debug.Log("单机模式启动");
                ClientUtility.StartSync(null, null, a => { a?.Invoke(); });
                GameObject.Destroy(gameObject.GetComponent<NetworkClient>());
            }
            
           // IBehaviour.BindUnityBehaviour<PvpCore>();
        }

        private void LateUpdate()
        {
            //本地逻辑帧跟服务器逻辑同步
        }

        private void Start()
        {
        }

        #region IFrameLog & IFrameParser
        public void LogInfo(string msg)
        {
            GameFramework.GameFrameworkLog.Info(msg);
        }

        public void LogWarning(string msg)
        {
            GameFramework.GameFrameworkLog.Warning(msg);
        }

        public void LogError(string msg)
        {
           // Debug.LogError(msg);
           GameFramework.GameFrameworkLog.Error(msg);
        }

        public object FromJson(string json, Type type)
        {
            return JsonUtility.FromJson(json, type);
        }

        public string ToJson(object data)
        {
            return JsonUtility.ToJson(data);
        }
        #endregion
    }
}